﻿using System;
using System.Collections.Generic;
using System.Threading;
using System.Text;

namespace TekaMUD.Engine.IO
{
	/// <summary>
	/// Helper class to hold channel output inside a using() {} block.
	/// </summary>
	public class ChannelOutputHolder : IDisposable
	{
		public BaseChannel Channel { get; private set; }
		private StringBuilder Builder { get; set; }

		public void Write(string str)
		{
			Builder.Append(str);
		}

		public string GetContents()
		{
			return Builder.ToString();
		}

		public ChannelOutputHolder(BaseChannel channel)
		{
			Builder = new StringBuilder();
			Channel = channel;
			channel.RegisterOutputHolder(this);
		}

		public void Dispose()
		{
			Channel.Flush(this);
		}
	}
}
